package com.ak.game.handler;

import com.ak.game.enums.GameEnum;
import com.ak.game.factory.GameFactory;
import com.ak.game.service.PnGameRecordService;
import com.ak.game.service.PnUserStreamService;
import com.ak.game.service.PnVipUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class FruitMachineHandler extends GameAbstractHandler{

    @Autowired
    private PnUserStreamService userStreamService;

    @Autowired
    private PnVipUserService vipUserService;

    @Autowired
    private PnGameRecordService gameRecordService;

    /**
     * 保存游戏记录
     *
     * @throws Exception
     */
    @Override
    public void gameResultRecord(Object game) throws Exception {
        gameRecordService.saveGameRecord(game,GameEnum.FruitMachine.tallyEnum());
    }

    /**
     * 用户下注
     *
     * @throws Exception
     */
    @Override
    public boolean userBetting(Object data, Object game) throws Exception {
        return userStreamService.saveUserBetting(GameEnum.FruitMachine.tallyEnum(), data, game);
    }

    /**
     * 单个用户对局结果
     *
     * @throws Exception
     */
    @Override
    public void userResultRecord(Object data, Object game) throws Exception {
        userStreamService.saveUserResultRecord(GameEnum.FruitMachine.tallyEnum(), data, game);
    }

    /**
     * 用户登录
     *
     * @throws Exception
     */
    @Override
    public boolean loginIn(Object data) throws Exception {
        return vipUserService.loginIn(data);
    }

    /**
     * 用户退出登录
     *
     * @throws Exception
     */
    @Override
    public void loginOut() throws Exception {
        super.loginOut();
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        GameFactory.register(GameEnum.FruitMachine.getGameId(), this);
    }

}
